package org.pictual.controller.mainPackage;

import java.io.BufferedReader;

public class WikiParser extends MyParser {

    BufferedReader input;

    static String wikiOrg = "wikipedia.org/wiki/";
    static String liClassStartWith = "<li class=\"interwiki-";
    private static final String[] _langShortcuts = {
        "en","es"
    };

    WikiParser(BufferedReader input) {
        this.input = input;
    }

    public String Parse(int lang2) {
        String result = null;
        String line;

        String fullLangClass = liClassStartWith + _langShortcuts[lang2] + "\">";
        try {
            while ((line = input.readLine()) != null) {
                String cleanline = line.replaceAll("\t", "");
                if (cleanline.startsWith(fullLangClass)) {
                    /*
protected int advanceChars(String line, int indexBegin, int n, String chars){*/
                   int index = advanceChars(cleanline,fullLangClass.length(),1,wikiOrg);
                   result = extractField(cleanline,index);
                }
            }
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return result;
    }
}
